package com.thinkverse.eureka.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.eureka.server.event.*;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * Eureka 实例事件监听器
 * 监听服务注册、下线、续约等事件
 */
@Slf4j
@Component
public class EurekaInstanceEventListener {

    /**
     * 服务注册事件
     */
    @EventListener
    public void listen(EurekaInstanceRegisteredEvent event) {
        log.info("服务注册成功: {} - {}", 
                event.getInstanceInfo().getAppName(), 
                event.getInstanceInfo().getInstanceId());
    }

    /**
     * 服务下线事件
     */
    @EventListener
    public void listen(EurekaInstanceCanceledEvent event) {
        log.info("服务下线: {} - {}", 
                event.getAppName(), 
                event.getServerId());
    }

    /**
     * 服务续约事件
     */
    @EventListener
    public void listen(EurekaInstanceRenewedEvent event) {
        log.debug("服务续约: {} - {}", 
                event.getInstanceInfo().getAppName(), 
                event.getInstanceInfo().getInstanceId());
    }

    /**
     * Eureka Server 启动事件
     */
    @EventListener
    public void listen(EurekaRegistryAvailableEvent event) {
        log.info("Eureka Server 注册中心已启动并可用");
    }

    /**
     * Eureka Server 启动完成事件
     */
    @EventListener
    public void listen(EurekaServerStartedEvent event) {
        log.info("Eureka Server 启动完成");
    }
}
